/*********************************************************************************************************************
 * COPYRIGHT NOTICE
 * Copyright (c) 2018,逐飞科技
 * All rights reserved.
 * 技术讨论QQ群：	一群：179029047(已满)
 *					二群：244861897(已满)
 *					三群：824575535
 *
 * 以下所有内容版权均属逐飞科技所有，未经允许不得用于商业用途，
 * 欢迎各位使用并传播本程序，修改内容时必须保留逐飞科技的版权声明。
 *
 * @file			zf_adc.h
 * @company			成都逐飞科技有限公司
 * @author			逐飞科技(QQ3184284598)
 * @version			查看doc内version文件 版本说明
 * @Software		IAR 8.3 or MDK 5.24
 * @Taobao			https://seekfree.taobao.com/
 * @date			2020-03-25
 * @note			本文件作为 LPC55S 系列芯片开源库外设文件
					提供 ADC 外设驱动
 ********************************************************************************************************************/

#ifndef _ZF_ADC_H_
#define _ZF_ADC_H_

#include "fsl_lpadc.h"

// *********************************************************** Param define *********************************************************** start

// ========== ADC 通道对应选项 ==========
typedef enum
{
	ADC_ASIDE_CH0 = 0x00,
	ADC_ASIDE_CH1 = 0x01,
	ADC_ASIDE_CH2 = 0x02,
	ADC_ASIDE_CH3 = 0x03,
	ADC_ASIDE_CH4 = 0x04,

	ADC_BSIDE_CH0 = 0x10,
	ADC_BSIDE_CH1 = 0x11,
	ADC_BSIDE_CH2 = 0x12,
	ADC_BSIDE_CH3 = 0x13,
	ADC_BSIDE_CH4 = 0x14,

	ADC_DIFF_CH0 = 0x20,
	ADC_DIFF_CH1 = 0x21,
	ADC_DIFF_CH2 = 0x22,
	ADC_DIFF_CH3 = 0x23,
	ADC_DIFF_CH4 = 0x24,

	ADC_CPU_TEMP = 0x05,
}adc_channel_list;
// ========== ADC 通道对应选项 ==========

// -------------------- ADC config --------------------
// ========== ADC 参数对应选项 ==========
typedef enum
{
	ADC_PARAM_DOZE_MODE,
	ADC_PARAM_AVERAGE_MODE,
	ADC_PARAM_PRELIMINARY_ENABLE,
	ADC_PARAM_POWER_DELAY,
	ADC_PARAM_REF_SELECT,
	ADC_PARAM_POWER_LEVEL,
	ADC_PARAM_PRIORITY_POLICY,
	ADC_PARAM_PAUSE_ENABLE,
	ADC_PARAM_PAUSE_DELAY,
	ADC_PARAM_FIFO0_MARK,
	ADC_PARAM_FIFO1_MARK,
}adc_param_list;
// ========== ADC 参数对应选项 ==========

// ========== ADC 等待模式对应选项 ==========
typedef enum
{
	ADC_DOZE_MODE_DISANLE = false,
	ADC_DOZE_MODE_ENANLE = true,
}adc_doze_mode_list;
// ========== ADC 等待模式对应选项 ==========

// ========== ADC 平均采样对应选项 ==========
typedef enum
{
	ADC_AVERAGE_MODE_1,
	ADC_AVERAGE_MODE_2,
	ADC_AVERAGE_MODE_4,
	ADC_AVERAGE_MODE_8,
	ADC_AVERAGE_MODE_16,
	ADC_AVERAGE_MODE_32,
	ADC_AVERAGE_MODE_64,
	ADC_AVERAGE_MODE_128,
}adc_average_mode_list;
// ========== ADC 平均采样对应选项 ==========

// ========== ADC 预启动对应选项 ==========
typedef enum
{
	ADC_PRELIMINARY_DISANLE = false,
	ADC_PRELIMINARY_ENANLE = true,
}adc_preliminary_enable_list;
// ========== ADC 预启动对应选项 ==========

// ========== ADC 选择基准电压对应选项 ==========
typedef enum
{
	ADC_REF_SELECT_VDDA = 1,
	ADC_REF_SELECT_VREFP = 2,
}adc_ref_select_list;
// ========== ADC 选择基准电压对应选项 ==========

// ========== ADC 电源设置对应选项 ==========
typedef enum
{
	ADC_POWER_LEVEL_LOWEST = 0,
	ADC_POWER_LEVEL_0B0,
	ADC_POWER_LEVEL_0B1,
	ADC_POWER_LEVEL_HIGHEST,
}adc_power_level_list;
// ========== ADC 电源设置对应选项 ==========

// ========== ADC 转换优先级对应选项 ==========
typedef enum
{
	ADC_PRIORITY_POLICY_IMMEDIATELY,
	ADC_PRIORITY_POLICY_SOFTLY,
	ADC_PRIORITY_POLICY_SUBSEQUENTLY,
}adc_priority_policy_list;
// ========== ADC 转换优先级对应选项 ==========

// ========== ADC 转换间隔对应选项 ==========
typedef enum
{
	ADC_PAUSE_DISABLE = false,
	ADC_PAUSE_ENABLE = true,
}adc_pause_enable_list;
// ========== ADC 转换间隔对应选项 ==========
// -------------------- ADC config --------------------

// -------------------- ADC conv command config --------------------
// ========== ADC 转换命令参数对应选项 ==========
typedef enum
{
	ADC_CONVCMD_PARAM_SAMPLE_MODE,
	ADC_CONVCMD_PARAM_CHANNEL_NUM,
	ADC_CONVCMD_PARAM_NEXT_CMD,
	ADC_CONVCMD_PARAM_AUTO_INCREMENT,
	ADC_CONVCMD_PARAM_CMD_LOOP,
	ADC_CONVCMD_PARAM_HWAVERAGE_MODE,
	ADC_CONVCMD_PARAM_SAMPLE_TIMER,
	ADC_CONVCMD_PARAM_HWCOMPARE_MODE,
	ADC_CONVCMD_PARAM_HWCOMPARE_HIGH,
	ADC_CONVCMD_PARAM_HWCOMPARE_LOW,
	ADC_CONVCMD_PARAM_RESOLUTION_MODE,
	ADC_CONVCMD_PARAM_WAIT_TRIGGER,
}adc_convcmd_param_list;
// ========== ADC 转换命令参数对应选项 ==========

// ========== ADC 转换模式对应选项 ==========
typedef enum
{
	ADC_SAMPLE_MODE_SINGLE_A,
	ADC_SAMPLE_MODE_SINGLE_B,
	ADC_SAMPLE_MODE_DIFF_AB,
	ADC_SAMPLE_MODE_BOTH_AB,
}adc_sample_mode_list;
// ========== ADC 转换模式对应选项 ==========

// ========== ADC 自动增量对应选项 ==========
typedef enum
{
	ADC_AUTO_INCREMENT_DISABLE = false,
	ADC_AUTO_INCREMENT_ENABLE = true,
}adc_auto_increment_list;
// ========== ADC 自动增量对应选项 ==========

// ========== ADC 硬件采样平均对应选项 ==========
typedef enum
{
	ADC_HWAVERAGE_MODE_1,
	ADC_HWAVERAGE_MODE_2,
	ADC_HWAVERAGE_MODE_4,
	ADC_HWAVERAGE_MODE_8,
	ADC_HWAVERAGE_MODE_16,
	ADC_HWAVERAGE_MODE_32,
	ADC_HWAVERAGE_MODE_64,
	ADC_HWAVERAGE_MODE_128,
}adc_hwaverage_mode_list;
// ========== ADC 硬件采样平均对应选项 ==========

// ========== ADC 采样时间对应选项 ==========
typedef enum
{
	ADC_SAMPLE_TIMER_3CYCLES,
	ADC_SAMPLE_TIMER_5CYCLES,
	ADC_SAMPLE_TIMER_7CYCLES,
	ADC_SAMPLE_TIMER_11CYCLES,
	ADC_SAMPLE_TIMER_19CYCLES,
	ADC_SAMPLE_TIMER_35CYCLES,
	ADC_SAMPLE_TIMER_67CYCLES,
	ADC_SAMPLE_TIMER_131CYCLES,
}adc_sample_time_list;
// ========== ADC 采样时间对应选项 ==========

// ========== ADC 硬件比较对应选项 ==========
typedef enum
{
	ADC_HWCOMPARE_MODE_DISABLE,
	ADC_HWCOMPARE_MODE_STORE,
	ADC_HWCOMPARE_MODE_REPEAT,
}adc_hwcompare_mode_list;
// ========== ADC 硬件比较对应选项 ==========

// ========== ADC 采样精度对应选项 ==========
typedef enum
{
	ADC_RESOLUTION_MODE_12BIT,
	ADC_RESOLUTION_MODE_16BIT,
}adc_resolution_mode_list;
// ========== ADC 采样精度对应选项 ==========

// ========== ADC 触发等待对应选项 ==========
typedef enum
{
	ADC_WAIT_TRIGGER_DISABLE = false,
	ADC_WAIT_TRIGGER_ENABLE = true,
}adc_wait_trigger_list;
// ========== ADC 触发等待对应选项 ==========
// -------------------- ADC conv command config --------------------

// -------------------- ADC conv trigger config --------------------
// ========== ADC 转换信号参数对应选项 ==========
typedef enum
{
	ADC_CONVTRIGGER_PARAM_CMD_ID,
	ADC_CONVTRIGGER_PARAM_DELAY_POWER,
	ADC_CONVTRIGGER_PARAM_PRIORITY,
	ADC_CONVTRIGGER_PARAM_CHA_FIFOSET,
	ADC_CONVTRIGGER_PARAM_CHB_FIFOSET,
	ADC_CONVTRIGGER_PARAM_HWTRIGGER,
}adc_convtrigger_param_list;

typedef enum
{
	ADC_FIFOSET_0,
	ADC_FIFOSET_1,
}adc_fifoset_list;
// ========== ADC 转换信号参数对应选项 ==========
// -------------------- ADC conv trigger config --------------------
// *********************************************************** Param define *********************************************************** start

void zf_adc_get_default_config (lpadc_config_t *config);
void zf_adc_param_set (lpadc_config_t *config, adc_param_list index, uint32_t data);
void zf_adc_convcmd_get_default_config (lpadc_conv_command_config_t *config);
void zf_adc_convcmd_param_set (lpadc_conv_command_config_t *config, adc_convcmd_param_list index, uint32_t data);
void zf_adc_convtrigger_get_default_config (lpadc_conv_trigger_config_t *config);
void zf_adc_convtrigger_param_set (lpadc_conv_trigger_config_t *config, adc_convtrigger_param_list index, uint32_t data);

void zf_adc_init (lpadc_config_t *config);
void zf_adc_default_init (void);
void zf_adc_sample_init (adc_channel_list ch_index, lpadc_conv_trigger_config_t adc_convtrigger_config, lpadc_conv_command_config_t adc_convcmd_config);
void zf_adc_sample_default_init (adc_channel_list ch_index);
void zf_adc_diff_sample_init (adc_channel_list ch_index);
void zf_adc_cpu_temp_init (void);
uint16_t zf_adc_get_voltage (adc_channel_list ch_index);
int16_t zf_adc_get_diff_voltage (adc_channel_list ch_index);
float zf_adc_get_cpu_temp (void);

#endif
